Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: '标题'
    },
    showtitle: {
      type: Boolean,
      value: true
    },
    placeholder: {
      type: String,
      value: '请输入'
    },
    multilines: {
      type: Boolean,
      value: false
    },
    singleline: {
      type: Boolean,
      value: true
    },
    name: {
      type: String,
      value: ''
    },
    showUploadImg: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    formData: {},
    imgUrl: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setForm: function(arg){
      // console.log('input change:', arg);
      var name = arg.currentTarget.dataset.name;
      var value = arg.detail.value;
      // console.log('name:', name, 'value:', value);
      this.triggerEvent('input', {
        name: name,
        value: value
      }, {});
    },

    selectImg: function(){
      let that = this;
      wx.chooseMedia({
        count: 1,
        mediaType: ['image']
      }).then((res) => {
        console.log('get image:', res.tempFiles);
        that.setData({
          imgUrl: res.tempFiles[0].tempFilePath
        });
        that.triggerEvent('change', {
          url: res.tempFiles[0].tempFilePath
        }, {});
      }).catch((res) => {
        console.log('cancel selection');
      });
    },

    delImg: function(){
      this.setData({
        imgUrl: ''
      });
      this.triggerEvent('change', {
        url: ''
      }, {});
    }
  }
})
